package com.bestv.search.management.datasyn.spider;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class SpiderSyncerManager extends QuartzJobBean {

    private static boolean isRunning = false;
    private Logger logger = Logger.getLogger(SpiderSyncerManager.class);

    @Override
    protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
        if (!isRunning) {
            isRunning = true;
            logger.info("Start sync info from system search_spider");

            // Sync youku base info
            SpiderBaseInfoSyncer baseInfoSyncer = new SpiderBaseInfoSyncer();
            baseInfoSyncer.syncYouKuBaseInfo();

            // Sync douban base info
            SpiderBaseInfoSyncer baseDoubanInfoSyncer = new SpiderBaseInfoSyncer();
            baseDoubanInfoSyncer.syncDouBanBaseInfo();

            // Sync hot comments
            SpiderCommentsSyncer commentSyncer = new SpiderCommentsSyncer();
            commentSyncer.sync();

            // Sync review
            SpiderReviewsSyncer reviewSyncer = new SpiderReviewsSyncer();
            reviewSyncer.sync();

            // Sync person
            SpiderPersonSyncer personSyncer = new SpiderPersonSyncer();
            personSyncer.sync();

            isRunning = false;
            logger.info("End sync info from system search_spider");
        } else {
            logger.info("Last sync process is still running");
        }
    }
}